package com.googlecode.perfectable.eventable.sourcing;

import com.googlecode.perfectable.eventable.sourcing.Transaction.Rollback;

public interface Operation {
	void perform() throws Rollback;

	Operation merge(Operation operation);

	public static final Operation NULL = new Operation() {
		@Override
		public void perform() throws Rollback {
			// noop
		}

		@Override
		public Operation merge(Operation operation) {
			return operation;
		}
	};

	public static final Operation INVALID = new Operation() {
		@Override
		public void perform() throws Rollback {
			throw new Rollback();
		}

		@Override
		public Operation merge(Operation operation) {
			return INVALID;
		}
	};
}
